% Define the function for quadratic B-spline using the Cox-de Boor recursion formula
function y = B(i, n, x, t)
    if n == 0
        y = (x >= t(i) & x < t(i+1));
    else
        div1 = t(i+n) - t(i);
        term1 = 0;
        if div1 ~= 0  % Avoid division by zero
            term1 = ((x - t(i)) / div1) .* B(i, n-1, x, t);
        end
        
        div2 = t(i+n+1) - t(i+1);
        term2 = 0;
        if div2 ~= 0  % Avoid division by zero
            term2 = ((t(i+n+1) - x) / div2) .* B(i+1, n-1, x, t);
        end
        
        y = term1 + term2;
    end
end